/*BX58ZUlza8WtbOUtymimPzFeuLbbjXbTgWD6t4EnGsq8HCE+ObHzZAO3tMfvwzEV*/
/*
 * @Descripttion: 生成客户弹窗相关方法(卡片/列表公用)
 * @version:
 * @Author: Chendch
 * @Date: 2021-01-03 13:55:32
 * @LastEditors: Chendch
 * @LastEditTime: 2021-01-03 14:22:05
 */
import {promptBox,ajax, toast } from "nc-lightapp-front";
import { validateFormulaSetting, getCurParam  } from './SupplierUtils';
import {Urls} from "../main/CONSTANCE";
 /**
     * 生成客户弹窗内容
*/
function createCustContent() {
    const onAfterCreateCustEvent = function(){}
    const {form} = this.props;
    const {createForm} = form;
    return createForm('createCust',{onAfterEvent: onAfterCreateCustEvent.bind(this)});
}
/**
 * 生成客户确认按钮点击前 事件
 */
function onCreateCustSureBtnClick(callback,destroyHotKeys) {
    destroyHotKeys(true,()=>{
        if(!this.props.form.isCheckNow('createCust')){
            destroyHotKeys(false);
            return;
        }
        let custData = this.props.form.getAllFormValue('createCust');
        let pk_supplier = custData.rows[0].values.pk_supplier.value;
        custData.status = '2';
        custData.areacode = 'createCust';
        let param = getCurParam.call(this,'pk_supplier',this.state.selectedRecords);
        let data = {
            model:custData,
            pageid:this.props.pagecode
        };
        validateFormulaSetting.call(this,data,()=>{
            ajax({
                url:Urls.saveCreateCustUrl,
                data:{form:data,tsMap:param.tsMap},
                success:(res)=>{
                    destroyHotKeys(false,()=>{
                        this.onAfterDialogClose(()=>{
                            toast({title:this.Lang['10140SUG-000069'],color:'success'});
                            this.state.openCard?this.initPageData(this.setCardValue,this.setCardStatus):this.onSearch({checagepage:true},this.setTableData)
                        })
                    })
                },
                error:(e)=>{destroyHotKeys(false,()=>{
                    toast({title:e.message,color:'error'});
                    throw new Error(e);
                })}
            })
        },{'creatCust':'form'},'form');
    })
}
/**
 * 生成客户取消按钮点击事件
 * @param callback
 */
function onCreateCustCancelBtnClick(callback,destroyHotKeys) {
    destroyHotKeys(true,()=>{
        promptBox({
            color:'warning',
            title:this.Lang['10140SUG-000077'],/* 国际化处理： 询问*/
            content:this.Lang['10140SUG-000068'],/* 国际化处理： 是否确认要取消？*/
            beSureBtnClick:()=>{
                destroyHotKeys(false,()=>{
                    this.Dialog.closeDialog(this.onAfterDialogClose);
                });
            },
            cancelBtnClick:()=>{destroyHotKeys(false);}
        })
    })
}
/**
 * 生成客户弹窗关闭后事件
 */
function onAfterCreateCustClose(){
    this.setState({openCreateCust:false});
}

export {
    createCustContent,
    onCreateCustSureBtnClick,
    onCreateCustCancelBtnClick,
    onAfterCreateCustClose
}
/*BX58ZUlza8WtbOUtymimPzFeuLbbjXbTgWD6t4EnGsq8HCE+ObHzZAO3tMfvwzEV*/
